﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using University.Workshop.Presenters.Users;

namespace University.Workshop.Presentation.Users
{
    /// <summary>
    /// Interaction logic for PageSecondStepModifyUser.xaml
    /// </summary>
    public partial class PageSecondStepModifyUser : Page, ISecondStepForModifyUser
    {
        private PresenterSecondStepForModifyUser pSecondStepForModifyUser;
        private PresenterModifyUserView pInternal;
        Boolean underlineLogin, primerLogin;
        string antiguoLogin;

        public PageSecondStepModifyUser(PresenterModifyUserView pExternal)
        {
            InitializeComponent();
            underlineLogin = true;
            primerLogin = true;
            pSecondStepForModifyUser = new PresenterSecondStepForModifyUser(this);
            this.pInternal = pExternal;
        }


        #region Miembros de IRegisterBasicView




        /*public Model.Kardex KardexProductToRegister
        {
            get;
            set;
        }*/

        public void Update()
        {
            // -
            pSecondStepForModifyUser.UpdateData();
        }

        public string SystemMessage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                pInternal.NotifySystemMessage(value);
            }
        }

        public string ErrorMessage
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                pInternal.NotifyErrorMessage(value);
            }
        }

        public void ChargeDataToBasic()
        {
            pSecondStepForModifyUser.ChargeDataUser();
        }

        public void GoNextPage()
        {

        }

        public void GoBackPage()
        {
            pInternal.GoStepOne();
        }

        #endregion


        #region Miembros de ISecondStepForRegisterUser

        public Model.User UserToModify
        {
            get;
            set;
        }

        public string Login
        {
            get
            {
                return LoginTxt.Text;
            }
            set
            {
                if (primerLogin)
                {
                    antiguoLogin = value;
                    primerLogin = false;
                }
                LoginTxt.Text = value;
            }
        }


        public string AntiguoLogin
        {
            get
            {
                return antiguoLogin;
            }
            set
            {
                AntiguoLogin = antiguoLogin;
            }
        }

        /*public string Password
        {
            get
            {
                return PasswordTxt.Text;
            }
            set
            {
                PasswordTxt.Text = value;
            }
        }

        public string RetryPassword
        {
            get
            {
                return RetypePasswordTxt.Text;
            }
            set
            {
                RetypePasswordTxt.Text = value;
            }
        }*/

        public int Role
        {
            get
            {
                return cbxRole.SelectedIndex;
            }
            set
            {
                cbxRole.SelectedIndex = value;
            }
        }

        public string PersonId
        {
            get
            {
                throw new NotImplementedException();
            }
            set
            {
                throw new NotImplementedException();
            }
        }


        #endregion





        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            App.Current.MainWindow.Title = "Modificar Usuario";
        }


        private void CantCupyPasteOrCut(object sender, CanExecuteRoutedEventArgs e)
        {
            if (e.Command == ApplicationCommands.Copy)
                e.Handled = true;
            if (e.Command == ApplicationCommands.Cut)
                e.Handled = true;
            if (e.Command == ApplicationCommands.Paste)
                e.Handled = true;
        }

        private void PersonNamesTxt_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            string temporal = ((TextBox)sender).Text + e.Text;
            foreach (char ch in e.Text)
            {
                e.Handled = !(char.IsLetterOrDigit(ch));
            }

            if (!e.Handled)
            {
                underlineLogin = true;
            }
            else
            {
                if (underlineLogin)
                {
                    foreach (char ch in e.Text)
                    {
                        e.Handled = !(ch.Equals('_'));
                    }
                    if (!e.Handled)
                        underlineLogin = false;
                }
            }
        }

        private void PersonNamesTxt_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (e.Key == Key.Space)
            {
                e.Handled = true;
            }
        }




    }
}
